package com.thoughtworks;

import java.util.List;

public class RenderHalf extends Render {

    public RenderHalf(String orderDetails, int originalPrice, int finalPrice, String[] ids, int[] numbers){
        super(orderDetails, originalPrice, finalPrice, ids, numbers);
        this.orderDetails = orderDetails;
        this.finalPrice = finalPrice;
        this.originalPrice = originalPrice;
        this.ids = ids;
        this.numbers = numbers;
    }

    public String renderApplication() {
        DataProvider dataProvider = new DataProvider();
        List<String> halfDishes = dataProvider.getHalfDishIds();
        String selectedHalf = "";
        for(String id: ids){
            if(halfDishes.indexOf(id)>=0){
                selectedHalf += helper.findItemName(id)+"，";
            }
        }
        orderDetails += "使用优惠:\n"
                + "指定菜品半价("+selectedHalf.substring(0,selectedHalf.length()-1)
                + ")，省" + (originalPrice-finalPrice) + "元\n"
                + "-----------------------------------\n"
                + "总计：" + finalPrice +"元\n"
                + "===================================";

        return orderDetails;
    }
}
